package com.sl.au.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.sl.au.entity.Account;
import com.sl.au.entity.ContractInfo;
import com.sl.au.entity.ExdeviPCAssInstructionExcuteWithPlan;
import com.sl.au.entity.Module;
import com.sl.au.entity.User;
import com.sl.au.service.ExdeviPCAssInstructionExcuteWithPlanService;



/**
 * 装配执行计划包含指导计划
 * @author Administrator
 *
 */
@RestController
@RequestMapping(value="/ui/viPCAssInstructionExcuteWithPlanView")
public class EXDEviPCAssInstructionExcuteWithPlanController extends BaseController{
	@Autowired
	ExdeviPCAssInstructionExcuteWithPlanService exdeviPCAssInstructionExcuteWithPlanService;
	
	@RequestMapping(method = RequestMethod.GET)
	public ModelAndView index() {
		ModelAndView modelAndView = this.createLayoutView("CustomerTotal/viPCAssInstructionExcuteWithPlanView");
		/*String businessGroup = "行业";
		List<Option> businesses = optionService.getRepository().findByGroup(businessGroup);
		modelAndView.addObject("businesses", businesses);*/
		return modelAndView;
	}
	
	@RequestMapping(value = "price", method = RequestMethod.GET)
	public Map<String, Object> getpricePage(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		int start = Integer.parseInt(request.getParameter("start"));
		int length = Integer.parseInt(request.getParameter("length"));
		String key = request.getParameter("key");
		List<ExdeviPCAssInstructionExcuteWithPlan> contracts = exdeviPCAssInstructionExcuteWithPlanService.getList(start, length, key);
		long count = exdeviPCAssInstructionExcuteWithPlanService.getCount(key);
		map.put("data", contracts);
		map.put("draw", request.getParameter("draw"));
		map.put("recordsFiltered", count);
		map.put("recordsTotal", count);
		return map;
	}
	/**
	 * HQL获取页面数据
	 */
	@RequestMapping(value = "getpage1", method = RequestMethod.POST)
	public Map<String, Object> getPage1(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		Map<String, Object> qMap = new HashMap<String, Object>();
		Map<String, Object> condition = new HashMap<String, Object>();
		Map<String, Object>numMap=new HashMap<String, Object>();
		int start = Integer.parseInt(request.getParameter("start"));
		int length = Integer.parseInt(request.getParameter("length"));
		Account a = this.getMyAccount();
		Module module = this.getPageModule("ExdeviPCAssInstructionExcuteWithPlan");
		//String dataFilter = module.getDataFilter();
		String dataFilter = "";
		User user = a.getUser();
		this.getQueryParams(qMap,numMap);
		condition.put("dataFilter", dataFilter);
		condition.put("qMap", qMap);
		condition.put("numMap", numMap);
		List<ExdeviPCAssInstructionExcuteWithPlan> contracts = exdeviPCAssInstructionExcuteWithPlanService.getQueryContractsHql(start, length, condition, user, "createTime",
				"desc");
		long count=exdeviPCAssInstructionExcuteWithPlanService.getQueryContractsHql(0, Integer.MAX_VALUE, condition, user, "createTime","desc").size();
		map.put("data", contracts);
		map.put("draw", request.getParameter("draw"));
		map.put("recordsFiltered", count);
		map.put("recordsTotal", count);
		return map;
	}
	
	private void getQueryParams(Map<String, Object> qMap,Map<String, Object>numMap){
//		String names[]={"supplierCode","contractType",
//				"auditState","belongArea","totalSum","stop",
//				"freightCharge","projectName","orderUnit","orderAddress",
//				"orderDelegate","orderPhone","orderZip","orderArea",
//				"postUnit","postAddress","postDelegate","postPhone","postZip"};
		String names[]={"cExcutePlanNumber","cContractNum",
				"cModel","cBTPart","cEqNo",
				"cType","cProcess","cState",
				"cPlanState","cCollarMemo","cTaskAssMemo",
				"cAssMemo","cTaskWaterTestMemo","cWaterTestMemo","cTasktPaintMemo","cPaintMemo","cTaskSealingMemo","cSealingMemo",
				"cTaskStorageMemo","cStorageMemo"};
		//String nums[]={"freightCharge","orderZip","postZip"};
		//String ints[]={"totalSum"};
		String dates[]={"dBeginCollarDate","dEndCollarDate","dTaskAcceptAssDate","dTaskSubmitAssDate",
				"dBeginAssDate","dEndAssDate","dTaskAcceptWaterTestDate","dTaskSubmitWaterTestDate","dBeginWaterTestDate",
				"dEndWaterTestDate","dTaskAcceptPaintDate"
				,"dTaskSubmitPaintDate","dBeginPaintDate","dEndPaintDate","dTaskAcceptSealingDate",
				"dTaskSubmitSealingDate","dBeginSealingDate","dEndSealingDate"
				,"dTaskAcceptStorageDate","dTaskSubmitStorageDate","dBeginStorageDate","dEndStorageDate"};
		for(String name:names){
			if(StringUtils.hasText(request.getParameter(name))){
				qMap.put(name, request.getParameter(name));
			}
		}
		for(String date:dates){
			if(null!=this.getDateQueryItem(date)){
				qMap.put(date,this.getDateQueryItem(date));
			}
		}
		/*if(null!=this.getDoubleQueryItem("totalSum")){
			qMap.put("totalSum",this.getDoubleQueryItem("totalSum"));
		}*/
		/*for(String n:nums){
			if(StringUtils.hasText(request.getParameter(n))){
				numMap.put(n, request.getParameter(n));
			}
		}*/
	}
}
